// locutor
// (c) 2009-2010, Normen Müller, normen.mueller@gmail.com  
// $Id: M.scala 94 2010-06-12 15:35:36Z normen.mueller $
package locutor

import scaup.Views._

import scalaxx.diff.EquivalenceSystem

import locutor.rws.RewriteSystem

/** Companion to <code>DocumentModel</code> class.
 * 
 *  @author <a href="mailto:normen.mueller@googlemail.com">Normen M&#xFC;ller</a>
 *  @version 0.0.5
 */
object DocumentModel { 
  /* System path to equivalence specifications
   */
  private val EQUIV_SPECS = System.getProperty("locutor.kb").toFile / "eq"
  
  /** Create a document model with an equivalence system and an empty rewrite system.
   * 
   *  @param equivSpec equivalence specification
   */
  def apply(equivSpec: String): DocumentModel = apply(EquivalenceSystem.parse(EQUIV_SPECS / equivSpec), RewriteSystem.empty)
  
  /** Create a document model with an equivalence system and a rewrite system.
   * 
   *  A rewite system is specified by either a graph model specification, or a rule system specification.
   *  In case of a rule system specification the rule sytem has to refer to the corresponding graph model specification.
   * 
   *  @param equivSpec equivalence specification
   *  @param rwsSpec   either a graph model specification or a rule system specification. 
   */
  def apply(equivSpec: String, rwsSpec: String): DocumentModel = apply(EquivalenceSystem.parse(EQUIV_SPECS / equivSpec), RewriteSystem.parse(rwsSpec))
  
  /** Create a document model with an equivalence system and a rewrite sytem.
   * 
   *  @param equivSystem   equivalence specification
   *  @param rewriteSystem rewrite system     
   */
  def apply(equivSystem: EquivalenceSystem, rewriteSystem: RewriteSystem): DocumentModel =
    if(equivSystem == null)
      error("Equivalence system may not be null.")
    else if(rewriteSystem == null)
      error("Rewrite system may not be null.")
    else new DocumentModel(equivSystem, rewriteSystem)  
}

/** A document model.
 * 
 *  @author <a href="mailto:normen.mueller@googlemail.com">Normen M&#xFC;ller</a>
 *  @version 0.0.5
 * 
 *  @todo Make class abstract
 *  @todo Implement a default document model, i.e. a document model with default equivalence system, default graph model, and a default rule system.
 *    The default graph model might be generated if the corresponding document/ document type is provided.  Otherwise an empty graph model
 *    extending the MoC graph model is generated.  The default rule system might be an empty one extending the MoC rule system.
 * 
 *  @param equivSystem   equivalence system
 *  @param rewriteSystem rewrite system
 */
class DocumentModel private[locutor] (val equivSystem: EquivalenceSystem, val rewriteSystem: RewriteSystem)
